/**
 * 建造者模式

 * 关心的是创建的过程而不是结果，一般用于创建复杂的对象
 */
// 下面是创建一个求职者对象

// 创建一个人类
var Human = function (param) {
  // 技能
  this.skill = param && param.skill || '保密';
  // 兴趣爱好
  this.hobby = param && param.hobby || '保密';
}

// 人这个类上面的原型和方法
Human.prototype = {
  getSkill: function () {
    return this.skill
  },
  getHobby: function () {
    return this.hobby;
  }
}

// 姓名类
var Named = function(name){
  var that = this;  
  (function(name, that){
    that.wholename = name;
    if(name.indexOf(' ')> -1){
      that.FirstName = name.slice(0,name.indexOf(' '))
      that.secondName = name.slice(name.indexOf(' '))
    }
  })(name, that)
}
// 职位类
var Work = function(work){
  var that = this;
  (function(work, that){
    switch(work){
      case 'code':
        that.work =  '工程师';
        that.workDescript = '我每天沉醉于编程';
      case 'teach':
        that.work = '教师';
        that.workDescript = '分享也是一种快乐';
      default :
        that.work = work;
        that.workDescript = '对不起，我们不清楚您选择的职位相关描述'
    }
  })(work, that)
}
Work.prototype = function(work){
  this.work = work
}
Work.prototype.changeDescript = function(setence){
  this.workDescript = setence
}
// /**
//  * 应聘者建造者
//  * 参数：name
//  * 参数：work
// // 

var Person = function(name, work){
  // 创建应聘者缓存对象
  var _person = new Human();
  _person.name = new Named(name);
  _person.work = new Work(work)
  return _person
}

var person = new Person('xiao ming','code')
console.log(person.name.FirstName)

